﻿@model DLM.Web.ViewModel.CountrySelectionPageView
@using DLM.Domain.DTO;
@using DLM.Services.Implementations;
@{
    var provinces = PageDataService.ShowProvince();

}
<script type="text/javascript">
    $(document).ready(function () {
        //$('#ddlProvince option:first').attr('selected', 'selected');
        $("#ddlProvince").change(function () {
            var province = $("#ddlProvince").find("option:selected").val();
            $.getJSON("/Common/FindCity", { province: province }, function (data) {
                var ddlCity = $("#ddlCity");
                ddlCity.empty();
                ddlCity.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlCity.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

        $("#ddlCity").change(function () {
            var city = $("#ddlCity").find("option:selected").val();
            $.getJSON("/Common/FindZone", { city: city }, function (data) {
                var ddlZone = $("#ddlZone");
                ddlZone.empty();
                ddlZone.append($('<option/>', { value: '', text: "请选择" }));
                $.each(data, function (index, itemData) {
                    ddlZone.append($('<option/>', {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });

    });

</script>
<span>省份:</span>
@if (string.IsNullOrEmpty(Model.SelectedProvince))
{
    if (Request.RawUrl.Contains("/User/UserEdit/"))
    {
            @Html.DropDownListFor(x => x.SelectedProvince, new SelectList(provinces, "Value", "Text"), "请选择", new { @class = "select-validation-error", id = "ddlProvince" })

    }
    else
    {
            @Html.DropDownListFor(x => x.SelectedProvince, new SelectList(provinces, "Value", "Text"), "请选择", new { @class = "sel", id = "ddlProvince" })

    }

}
else
{
    @Html.DropDownListFor(x => x.SelectedProvince, new SelectList(provinces, "Value", "Text"), "请选择", new { @class = "sel", id = "ddlProvince" })

}
<span>城市:</span>
@if (string.IsNullOrEmpty(Model.SelectedCity))
{
    if (Request.RawUrl.Contains("/User/UserEdit/"))
    {
            @Html.DropDownListFor(x => x.SelectedCity, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "select-validation-error", id = "ddlCity" })

    }
    else
    {
             @Html.DropDownListFor(x => x.SelectedCity, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlCity" })

    }

}
else
{
    var cityList = new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "" },
                            new SelectListItem { Text = Model.SelectedCity, Value = Model.SelectedCity, Selected = true }
                           
                        };
    @Html.DropDownListFor(x => x.SelectedCity, cityList, new { @class = "sel", id = "ddlCity" })

}
<span>区:</span>
@if (string.IsNullOrEmpty(Model.SelectedZone))
{
    if (Request.RawUrl.Contains("/User/UserEdit/"))
    {
            @Html.DropDownListFor(x => x.SelectedZone, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "select-validation-error", id = "ddlZone" })

    }
    else
    { 
            @Html.DropDownListFor(x => x.SelectedZone, new SelectList(Enumerable.Empty<SelectListItem>()), "请选择", new { @class = "sel", id = "ddlZone" })

    }

}
else
{
    var zoneList = new List<SelectListItem> 
                        { new SelectListItem { Text = "请选择", Value = "" },
                            new SelectListItem { Text = Model.SelectedZone, Value = Model.SelectedZone, Selected = true }
                           
                        };
    @Html.DropDownListFor(x => x.SelectedZone, zoneList, new { @class = "sel", id = "ddlZone" })

}
